package com.hotline.monitor.listener;


import com.hotline.monitor.constant.Constants;
import com.hotline.monitor.service.agent.OnlineAgentService;
import com.hotline.monitor.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

@Slf4j
@WebListener
public class AppServletListener implements ServletContextListener {

    @Autowired
    private OnlineAgentService onlineAgentService;

    @Override
    public void contextInitialized(ServletContextEvent arg0) {
        String guid = onlineAgentService.login();
        if(StringUtils.isNotBlank(guid)){
            Constants.HEADER_GUID = guid;
        }
    }

    @Override
    public void contextDestroyed(ServletContextEvent arg0) {
        onlineAgentService.logout();
    }

}
